﻿using AutoMapper;
using KayakMes.Common.Dtos.WarehouseManageDto.Input;
using KayakMes.Common.Dtos.WarehouseManageDto.Output;
using KayakMes.Common.Result;
using KayakMes.WarehouseManage.Application;
using KayakMes.WarehouseManage.Domain.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Yitter.IdGenerator;

namespace KayakMes.WarehouseManage.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseAreaController : ControllerBase
    {
        private readonly IWarehouseManageServices services;

        public WarehouseAreaController(IWarehouseManageServices services)
        {
            this.services = services;
        }

        /// <summary>
        /// 添加库区
        /// </summary>
        /// <param name="purchaseOrderModel">库区模型</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPost]
        public ApiResult<int> AddWarehouseArea(WarehouseAreaAddDto dto)
        {
            return services.AddWarehouseArea(dto);
        }

        /// <summary>
        /// 更新库区信息
        /// </summary>
        /// <param name="purchaseOrderModel">库区模型</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPost]
        public ApiResult<int> UpdateWarehouseArea(WarehouseAreaModel model)
        {
            return services.UpdateWarehouseArea(model);
        }

        /// <summary>
        /// 逻辑删除库区
        /// 将库区的IsDeleted字段设置为true，而不是物理删除
        /// </summary>
        /// <param name="Id">库区ID</param>
        /// <returns>返回操作结果，成功返回1，失败返回0</returns>
        [HttpPost]
        public ApiResult<int> LogicDelWarehouseArea(long Id)
        {
           return services.LogicDelWarehouseArea(Id);
        }

        /// <summary>
        /// 获取库区列表（支持分页查询）
        /// </summary>
        /// <param name="dto">库区列表查询条件DTO</param>
        /// <returns>返回分页的库区列表</returns>
        [HttpGet]
        public ApiPaging<WarehouseAreaOutput> GetAllWarehouseArea([FromQuery]WarehouseAreaDto dto)
        {
            return services.GetAllWarehouseArea(dto);
        }

        /// <summary>
        /// 根据ID查询指定的库区
        /// </summary>
        /// <param name="id">库区ID</param>
        /// <returns>返回操作结果，包含指定的库区信息</returns>
        [HttpGet]
        public ApiResult<WarehouseAreaModel> GetWarehouseArea([FromQuery]long Id)
        {
            return services.GetWarehouseArea(Id);    
        }

        /// <summary>
        /// 随机生成库区编号
        /// </summary>
        /// <returns>字符串</returns>
        [HttpGet]
        public string GetWarehouseAreaCode()
        {
            return services.GetWarehouseAreaCode();
        }
        /// <summary>
        /// 仓库的下拉框数据
        /// </summary>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public ApiResult<List<WarehouseOutput>> ComboBoxWarehouse()
        {
            return services.ComboBoxWarehouse();
        }
    }
}
